var API = new importAPI();

function importAPI () {
	var _self = this;

	var requestDomain = "https://sephora.dhteam.net:7443/";
	_self.requestDomain = requestDomain

	function _Ajax(opts){
	    var type = opts.type || "POST";
		let data = {
	        type: type,
	        url: requestDomain + opts.API,
	        dataType: 'json',
	        async: true,
	        data: opts.data,
	        success: function(data){
                if (opts.onSuccess) opts.onSuccess(data);
	        },
	        error: function(){
	        	alert("网络可能存在问题，请刷新试试！");
	        }
	    }
		if(opts.token) {
			var token = localStorage.getItem('loginToken') || ''
			data.headers = {
				'Authorization':token
			}
		}
		if(opts.file){
			data.processData = false
			data.contentType = false
		}
	    $.ajax(data);
	}

	/**
     * 获取用户名
     * @param {*} onSuccess 回调函数
     */
	_self.GetUserName = function(data,onSuccess){
		_Ajax({
            API:"/api/sign/GetUserName",
			type: 'GET',
            data: data,
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 登录
     * @param {*} onSuccess 回调函数
     */
	 _self.Login = function(data,onSuccess){
		_Ajax({
            API:`/api/sign/Login?userid=${data.userid}&name=${data.name}`,
			type: 'POST',
            data: {},
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 获取用户进度
     * @param {*} onSuccess 回调函数
     */
	 _self.GetCurrentProcess = function(onSuccess){
		_Ajax({
            API:`/api/sign/GetCurrentProcess`,
			type: 'GET',
            data: {},
			token: true,
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 获取题目
     * @param {*} onSuccess 回调函数
     */
	 _self.GetQuestions = function(onSuccess){
		_Ajax({
            API:`/api/sign/GetQuestions`,
			type: 'GET',
            data: {},
			token: true,
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 回答题目
     * @param {*} onSuccess 回调函数
     */
	 _self.SubQuestion = function(data,onSuccess){
		_Ajax({
            API:`/api/sign/SubQuestion`,
			type: 'POST',
            data: data,
			token: true,
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 上传图片
     * @param {*} onSuccess 回调函数
     */
	 _self.UploadSFL = function(data,onSuccess){
		_Ajax({
            API:`/api/UploadManager/UploadSFL`,
			type: 'POST',
            data: data,
			token: true,
			file: true,
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 提交图片
     * @param {*} onSuccess 回调函数
     */
	 _self.subpicture = function(data,onSuccess){
		_Ajax({
            API:`/api/sign/subpicture`,
			type: 'POST',
            data: data,
			token: true,
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 抽奖
     * @param {*} onSuccess 回调函数
     */
	 _self.Lottery = function(onSuccess){
		_Ajax({
            API:`/api/sign/Lottery`,
			type: 'POST',
            data: {},
			token: true,
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 获取排行榜
     * @param {*} onSuccess 回调函数
     */
	 _self.getrank = function(onSuccess){
		_Ajax({
            API:`/api/sign/getrank`,
			type: 'GET',
            data: {},
			token: true,
            onSuccess:onSuccess
        });
    }//end func

	/**
     * 获取中奖名单
     * @param {*} onSuccess 回调函数
     */
	 _self.getcharge = function(onSuccess){
		_Ajax({
            API:`/api/sign/getcharge`,
			type: 'GET',
            data: {},
			token: true,
            onSuccess:onSuccess
        });
    }//end func

}//end import